﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Threading.Tasks;
using PublishNews.Entities;

namespace PublishNews.Repositories
{
    public class CategoryRepository : BaseRepository<Category> ,ICategoryRepository
    {

        public async Task<List<Category>> GetSubCategories(Guid? categoryId)
        {
            using (var context = Context)
            {
                if (categoryId.HasValue)
                {
                    return await context.Set<Category>().Where(x => x.ParentCategoryId == categoryId).ToListAsync();
                }
                else
                {
                    return await context.Set<Category>().Where(x => x.ParentCategoryId.HasValue == false).ToListAsync();
                }
            }
        }
    }
}